﻿using System;
using System.Collections.Generic;
using System.Text;
namespace JCW.Common
{
    public class Letter
    {
        #region 拼音处理
        /// <summary>
        /// 返回字符串各字首字母
        /// </summary>
        /// <param name="str">输入</param>
        /// <returns>输出字母</returns>
        public static string GetLetterFromString(string str)
        {
            string tempStr = "";
            if (!string.IsNullOrEmpty(str))
            {
                foreach (char c in str)
                {
                    if (((int)c >= 33) && ((int)c <= 126))
                    {
                        //字母和符号原样保留 
                        tempStr += c.ToString();
                    }
                    else
                    {
                        //累加拼音声母
                        tempStr += GetLetterFromChar(c.ToString());
                    }
                }
            }
            return tempStr;
        }


        /// <summary>
        /// 返回单个字的字母
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        private static string GetLetterFromChar(string str)
        {
            if (str.CompareTo("吖") < 0) return str;
            if (str.CompareTo("八") < 0) return "a";
            if (str.CompareTo("嚓") < 0) return "b";
            if (str.CompareTo("咑") < 0) return "c";
            if (str.CompareTo("妸") < 0) return "d";
            if (str.CompareTo("发") < 0) return "e";
            if (str.CompareTo("旮") < 0) return "f";
            if (str.CompareTo("铪") < 0) return "g";
            if (str.CompareTo("讥") < 0) return "h";
            if (str.CompareTo("咔") < 0) return "j";
            if (str.CompareTo("垃") < 0) return "k";
            if (str.CompareTo("嘸") < 0) return "l";
            if (str.CompareTo("拏") < 0) return "m";
            if (str.CompareTo("噢") < 0) return "n";
            if (str.CompareTo("妑") < 0) return "o";
            if (str.CompareTo("七") < 0) return "p";
            if (str.CompareTo("亽") < 0) return "q";
            if (str.CompareTo("仨") < 0) return "r";
            if (str.CompareTo("他") < 0) return "s";
            if (str.CompareTo("哇") < 0) return "t";
            if (str.CompareTo("夕") < 0) return "w";
            if (str.CompareTo("丫") < 0) return "x";
            if (str.CompareTo("帀") < 0) return "y";
            if (str.CompareTo("咗") < 0) return "z";
            return str;
        }
        #endregion
    }
}
